//-----------------------------------------------------------------------
// <copyright file="ClientInfo.cs" company="北京正奇联讯科技有限公司">
//      Copyright 2015, ZhengQi (Beijing) Video Technology Co.,Ltd. ALL RIGHTS RESERVED 
//   Permission is hereby granted to licensees of ZhengQi (Beijing) Video Technology Co.,Ltd. 
//   products to use or abstract this computer program for the sole purpose of implementing 
//   a product based on ZhengQi (Beijing) Video Technology Co.,Ltd.products. No other rights to 
//   reproduce, use, or disseminate this computer program,whether in part or in whole, are granted. 
//   ZhengQi (Beijing) Video Technology Co.,Ltd. makes no representation or warranties with 
//   respect to the performance of this computer program, and specifically disclaims any 
//   responsibility for any damages, special or consequential, connected with the use of 
//   this program. For details, see http://www.cdv.com/
// </copyright>
// <summary>
//    提供客户端信息的类
// </summary>
// <author>HouBaoZhu</author>
// <createTime>2017/10/25 17:25:28</createTime>
// <version>1.0</version>
// <modify></modify>
//-----------------------------------------------------------------------

namespace CDV.MC.MatrixDriver.WebApp.Data
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    /// <summary>
    /// 客户端信息类
    /// </summary>
    public class ClientInfo
    {
        /// <summary>
        /// 客户端与矩阵服务的初始连接时间
        /// </summary>
        [DisplayName("首次访问时间")]
        public DateTime FirstConnectTime { get; set; }
        public string FirstConnectTimeDisplay { get { return FirstConnectTime.ToString("yyyy/MM/dd HH:mm:ss"); } }

        /// <summary>
        /// 客户端与矩阵服务的最近一次连接时间
        /// </summary>
        [DisplayName("最近访问时间")]
        public DateTime LastConnectTime { get; set; }
        public string LastConnectTimeDisplay { get { return LastConnectTime.ToString("yyyy/MM/dd HH:mm:ss"); } }

        /// <summary>
        /// 客户端连接的矩阵信息(矩阵ID)
        /// </summary>
        [DisplayName("连接矩阵")]
        public IDictionary<int, string> ConnectedToMatrices { get; set; } = new Dictionary<int, string>();

        /// <summary>
        /// 客户端与矩阵服务的连接持续时间
        /// </summary>
        [DisplayName("持续连接时间")]
        public string Duration
        {
            get
            {
                return LastConnectTime.Subtract(FirstConnectTime).ToString(@"hh\:mm\:ss");
            }
        }

        /// <summary>
        /// 客户端用户ID
        /// </summary>
        [DisplayName("用户ID")]
        public string UserID { get; set; }

        /// <summary>
        /// 客户端主机名
        /// </summary>
        [DisplayName("主机名")]
        public string HostName { get; set; }

        /// <summary>
        /// 客户端网络IP地址
        /// </summary>
        [DisplayName("IP地址")]
        public string IP { get; set; }

        /// <summary>
        /// 客户端网络端口
        /// </summary>
        [DisplayName("端口")]
        public int Port { get; set; }

        /// <summary>
        /// 客户端在线状态
        /// </summary>
        [DisplayName("在线状态")]
        public bool IsOnline { get; set; }

        /// <summary>
        /// Web客户端标识
        /// </summary>
        [DisplayName("类别")]
        public bool IsWebClient { get; set; }

        /// <summary>
        /// 标识为自身
        /// </summary>
        public bool Self { get; set; }

        public override string ToString()
        {
            return $"{IP.Replace('.', '_')}_{Port}";
        }
    }
}